//带快递费的总额
var totalFee=0;
//不带快递费的总额
var fee=0;
 var productId = getUrlParam('productId');
 var num = getUrlParam('num');
 var normalId = getUrlParam('normalId');
 var memberId = getUrlParam('memberId');
var addressId=0;
var memo;
var serviceId;
var isSince;
$(function () {
    //productId=421&num=1&normalId=522&memberId=623



    getConfirmDetail(productId, num, normalId, memberId);


});

function toPeisong() {
    window.location.href="/service-add.html?addressId="+addressId;
}

function getConfirmDetail(productId, num, normalId, memberId) {

    $.ajax({
        type: "post",
        url: ajaxUrl + "/mobile/order/buyNowConfirmOrder",
        async: true,
        data: {'productId': productId, 'num': num, 'normalId': normalId, 'memberId': memberId},
        success: function (data) {
            console.log(data);
            var result = data.result;
            if (result.receiveAddress==null) {
                $('#addressTitle').text("新增地址");
            }else{
                setAddress(result.receiveAddress);
            }

            var productDetails = result.productDetails;
            setProductDetails(productDetails);
            $('#canGetScore').text(result.canGetScore+"积分");

            $('#proFee').text(result.totalFee+'元');

            $('#totalFee').text(result.totalFee+result.serviceFee);
            totalFee=result.totalFee+result.serviceFee;
            fee=result.totalFee;
            $('#serviceFee').text(result.serviceFee+'元');
            $('#totalNum').text(result.totalNum);

            var fwdHtml='';
            fwdHtml+='<div class="addr">'+result.servicePointDto.name+'   '+result.servicePointDto.mobile+'</div>';
            fwdHtml+='<div class="addr">'+result.servicePointDto.address+'</div>';
            $('#fwd').html(fwdHtml);
            serviceId=result.servicePointDto.id;
        }

    });
}

//设置详情
function setProductDetails(prodcutDetails) {
        var html='';
        for (var i=0;i<prodcutDetails.length;i++) {
            html += '<a href="javascript:;" class="order-item bottom-border">';
            html += '<img src="' + prodcutDetails[i].productImage + '" alt="" class="img">';
            html += '<div class="text">';
            html += '<div class="name">'+prodcutDetails[i].productName+'</div>';
            html += '';
            html += '</div>';
            html += '<div class="price-num">';
            html += '<div class="price"><i>￥</i>' + prodcutDetails[i].price + '</div>';
            html += '<div class="num">X ' + prodcutDetails[i].num + '</div>';
            html += '</div>'
        }
         $('#pList').html(html);
}

function setAddress(address) {
    $('#uname').html(address.name+'<i class="tel">'+address.mobile+'</i>');
    $('#addressName').text(address.provinceName+
        address.cityName+address.districtName+address.streetName+address.address);
    addressId=address.id;

}